package com.ncu702.backend.exception;

import com.ncu702.backend.common.BaseResponse;
import com.ncu702.backend.common.ErrorCode;
import com.ncu702.backend.common.ResultUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public BaseResponse<?> handleBusinessException(BusinessException ex) {
        return ResultUtils.error(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseResponse<?> handleException(Exception ex) {
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR, ex.getMessage());
    }
}
